package com.dtjd.playcoinmonkey.activities;

import android.annotation.SuppressLint;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.PopupMenu;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.bytedance.sdk.openadsdk.AdSlot;
import com.bytedance.sdk.openadsdk.TTAdConstant;
import com.bytedance.sdk.openadsdk.TTAdDislike;
import com.bytedance.sdk.openadsdk.TTAdNative;
import com.bytedance.sdk.openadsdk.TTAdSdk;
import com.bytedance.sdk.openadsdk.TTNativeExpressAd;
import com.bytedance.sdk.openadsdk.TTRewardVideoAd;
import com.dtjd.playcoinmonkey.ChildClick;
import com.dtjd.playcoinmonkey.MyApplication;
import com.dtjd.playcoinmonkey.R;
import com.dtjd.playcoinmonkey.adapter.CommentExpandAdapter;
import com.dtjd.playcoinmonkey.bean.CommentBean;
import com.dtjd.playcoinmonkey.bean.CommentDetailBean;
import com.dtjd.playcoinmonkey.bean.HttpParaBean;
import com.dtjd.playcoinmonkey.bean.ReplyDetailBean;
import com.dtjd.playcoinmonkey.databinding.ActivityPostDetailBinding;
import com.dtjd.playcoinmonkey.utils.Network;
import com.dtjd.playcoinmonkey.utils.Tools;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.header.ClassicsHeader;
import com.scwang.smart.refresh.layout.api.RefreshLayout;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class PostDetailActivity extends AppCompatActivity {
    private ActivityPostDetailBinding binding;
    private final List<CommentBean> data=new ArrayList<>();
    private int current=1;
    private CommentExpandAdapter adp;
    private ProgressDialog dialog;
    @RequiresApi(api = Build.VERSION_CODES.M)
    @SuppressLint({"StringFormatMatches", "SetTextI18n"})
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityPostDetailBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        setTitle(MyApplication.postBean.bp_title);
        Glide.with(this).load(MyApplication.postBean.wb_url).apply(RequestOptions.bitmapTransform(new CircleCrop())).placeholder(R.drawable.loading).placeholder(R.drawable.loading).error(R.drawable.loaderr).into(binding.postDetailIcon);
        binding.postDetailNickname.setText(MyApplication.postBean.wb_nickname);
        binding.postDetailTime.setText(MyApplication.postBean.time);
        binding.postDetailTitle.setText(MyApplication.postBean.bp_title);
        binding.postDetailContent.setText(MyApplication.postBean.bp_content.replace("http"," http").replace("：",":"));
        binding.postDetailPara.setText(String.format(getResources().getString(R.string.viewsNum),MyApplication.postBean.bp_click_number+1));
        binding.postdetailRefresh.setRefreshFooter(new ClassicsFooter(this));
        binding.postdetailRefresh.setRefreshHeader(new ClassicsHeader(this));
        binding.postDetailShare.setOnClickListener(view ->{
            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_TEXT, "https://yuanshijie.m2node.com/share_cn.html?id="+MyApplication.postBean.id);
            shareIntent.setType("text/plain");
            startActivity(Intent.createChooser(shareIntent, "Share to:"));
        } );
        if (!MyApplication.postBean.img.equals("")){
            binding.postDetailImg.setVisibility(View.VISIBLE);
            Glide.with(this).load(MyApplication.postBean.img).placeholder(R.drawable.loading).error(R.drawable.loaderr).into(binding.postDetailImg);
        }else{
            binding.postDetailImg.setVisibility(View.GONE);
        }
        binding.postDetailBack.setOnClickListener(view -> finish());
        adp = new CommentExpandAdapter(this, data, (v, pi) -> {
            if (MyApplication.needTicket){
            List<HttpParaBean> para=new ArrayList<>();
            para.add(new HttpParaBean("token","token"));
            Network.post(para, "wbhMain/getTickets", new Callback() {
                @Override
                public void onResponse(@NonNull Call call, @NonNull Response response) {
                    runOnUiThread(() -> {
                        try {
                            JSONObject jo = new JSONObject(response.body().string());
                            if (jo.getInt("code")==1){
                                if (jo.getJSONArray("datalist").getJSONObject(0).getInt("ticket")>0){
                                    Tools.showDialog(PostDetailActivity.this,
                                            String.format(getResources().getString(R.string.restTicket), jo.getJSONArray("datalist").getJSONObject(0).getInt("ticket")),
                                            String.format(getResources().getString(R.string.dialog_content_post), "1"),
                                            getResources().getString(R.string.cancel), (o, dialog) -> dialog.dismiss(), getResources().getString(R.string.confirm), (o, dialog) -> {
                                                dialog.dismiss();
                                                reply2(pi);
                                            });
                                }else {
                                    Tools.showDialog(PostDetailActivity.this,
                                            String.format(getResources().getString(R.string.restTicket), jo.getJSONArray("datalist").getJSONObject(0).getInt("ticket")),
                                            getResources().getString(R.string.ticketNotEnough),
                                            getResources().getString(R.string.watching),
                                            (o, dialog) -> {
                                                dialog.dismiss();
                                                /*
                                                看完后给三张扣除1张，
                                                 */
                                                lookAd((v1, position) -> reply2(pi));
                                            }, getResources().getString(R.string.cancel), (o, dialog) -> dialog.dismiss());
                                }
                            }else {
                                Tools.toast( getResources().getString(R.string.getTicketFaild));
                            }
                        } catch (JSONException | IOException e) {
                            e.printStackTrace();
                        }
                    });
                }
                @Override
                public void onFailure(@NonNull Call call, @NonNull IOException e) {
                    e.printStackTrace();
                }
            });
            }else {
                reply2(pi);
            }
        });
        binding.postdetailCommentList.setAdapter(adp);
        binding.postdetailCommentList.setOnChildClickListener((expandableListView, view, i, i1, l) -> {
            if (MyApplication.needTicket) {
                List<HttpParaBean> para = new ArrayList<>();
                para.add(new HttpParaBean("token", "token"));
                Network.post(para, "wbhMain/getTickets", new Callback() {
                    @Override
                    public void onResponse(@NonNull Call call, @NonNull Response response) {
                        runOnUiThread(() -> {
                            try {
                                JSONObject jo = new JSONObject(response.body().string());
                                if (jo.getInt("code") == 1) {
                                    if (jo.getJSONArray("datalist").getJSONObject(0).getInt("ticket") > 0) {
                                        Tools.showDialog(PostDetailActivity.this,
                                                String.format(getResources().getString(R.string.restTicket), jo.getJSONArray("datalist").getJSONObject(0).getInt("ticket")),
                                                String.format(getResources().getString(R.string.dialog_content_post), "1"),
                                                getResources().getString(R.string.cancel), (o, dialog) -> dialog.dismiss(), getResources().getString(R.string.confirm), (o, dialog) -> {
                                                    dialog.dismiss();
                                                    reply(i, i1);
                                                });
                                    } else {
                                        Tools.showDialog(PostDetailActivity.this,
                                                String.format(getResources().getString(R.string.restTicket), jo.getJSONArray("datalist").getJSONObject(0).getInt("ticket")),
                                                getResources().getString(R.string.ticketNotEnough),
                                                getResources().getString(R.string.watching),
                                                (o, dialog) -> {
                                                    dialog.dismiss();
                                                /*
                                                看完后给三张扣除1张，
                                                 */
                                                    lookAd((v, position) -> reply(i, i1));

                                                }, getResources().getString(R.string.cancel), (o, dialog) -> dialog.dismiss());
                                    }
                                } else {
                                    Tools.toast( getResources().getString(R.string.getTicketFaild));
                                }
                            } catch (JSONException | IOException e) {
                                e.printStackTrace();
                            }
                        });
                    }
                    @Override
                    public void onFailure(@NonNull Call call, @NonNull IOException e) {
                        e.printStackTrace();
                    }
                });
            }else {
                reply(i,i1);
            }
            return true;
        });
        binding.postdetailCommentList.setOnGroupExpandListener(i -> {
            CommentBean bean = data.get(i);
            bean.replyDetailBeans.clear();
            List<HttpParaBean> para=new ArrayList<>();
            para.add(new HttpParaBean("commentId",String.valueOf(bean.commentDetailBean.id)));
            para.add(new HttpParaBean("bpId",String.valueOf(MyApplication.postBean.id)));
            Network.post(para, "wbhMain/getReply", new Callback() {
                @Override
                public void onFailure(@NonNull Call call, @NonNull IOException e) {
                    e.printStackTrace();
                }
                @Override
                public void onResponse(@NonNull Call call, @NonNull Response response)  {
                    try {
                        JSONArray ja = new JSONObject(response.body().string()).getJSONArray("datalist");
                        for (int i = 0; i < ja.length(); i++) {
                            JSONObject jo = ja.getJSONObject(i);
                            bean.replyDetailBeans.add(new ReplyDetailBean(jo.getInt("bp_id"), jo.getInt("bu_id"), jo.getInt("id"), jo.getString("reply_content"), jo.getString("reply_nickname"), jo.getString("time"), jo.getString("wb_nickname"), jo.getString("wb_url")));
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    runOnUiThread(() -> adp.notifyDataSetChanged());
                }
            });
        });
        binding.postdetailCommentList.setOnGroupCollapseListener(i -> data.get(i).replyDetailBeans.clear());
        binding.postdetailRefresh.setOnLoadMoreListener(refreshLayout -> refreshComment(false,refreshLayout,null));
        binding.postdetailRefresh.setOnRefreshListener(refreshLayout -> {
            current=1;
            refreshComment(true,null,refreshLayout);
        });
        binding.postdetailSend.setOnClickListener(view -> {
            if (!binding.postDetailCommentEdit.getText().toString().equals("")){
                if (MyApplication.needTicket) {
                    List<HttpParaBean> para = new ArrayList<>();
                    para.add(new HttpParaBean("token", "token"));
                    Network.post(para, "wbhMain/getTickets", new Callback() {
                        @Override
                        public void onResponse(@NonNull Call call, @NonNull Response response) {
                            runOnUiThread(() -> {
                                try {
                                    JSONObject jo = new JSONObject(response.body().string());
                                    if (jo.getInt("code") == 1) {
                                        if (jo.getJSONArray("datalist").getJSONObject(0).getInt("ticket") > 0) {
                                            Tools.showDialog(PostDetailActivity.this,
                                                    String.format(getResources().getString(R.string.restTicket), jo.getJSONArray("datalist").getJSONObject(0).getInt("ticket")),
                                                    String.format(getResources().getString(R.string.dialog_content_post), "1"),
                                                    getResources().getString(R.string.cancel), (o, dialog) -> dialog.dismiss(), getResources().getString(R.string.confirm), (o, dialog) -> {
                                                        dialog.dismiss();
                                                        comment();
                                                    });
                                        } else {
                                            Tools.showDialog(PostDetailActivity.this,
                                                    String.format(getResources().getString(R.string.restTicket), jo.getJSONArray("datalist").getJSONObject(0).getInt("ticket")),
                                                    getResources().getString(R.string.ticketNotEnough),
                                                    getResources().getString(R.string.watching),
                                                    (o, dialog) -> {
                                                        dialog.dismiss();
                                                /*
                                                看完后给三张扣除1张，
                                                 */
                                                      lookAd((v, position) -> comment());

                                                    }, getResources().getString(R.string.cancel), (o, dialog) -> dialog.dismiss());
                                        }
                                    } else {
                                        Tools.toast( getResources().getString(R.string.getTicketFaild));
                                    }
                                } catch (JSONException | IOException e) {
                                    e.printStackTrace();
                                }
                            });
                        }
                        @Override
                        public void onFailure(@NonNull Call call, @NonNull IOException e) {
                            e.printStackTrace();
                        }
                    });
                }else {
                    comment();
                }
            }else {
                Tools.toast( getResources().getString(R.string.content_cant_blank));
            }
        });
        binding.postDetailFrozen.setOnClickListener(view -> {
            List<HttpParaBean> para=new ArrayList<>();
            para.add(new HttpParaBean("token","token"));
            para.add(new HttpParaBean("id",MyApplication.postBean.id));
            Network.post(para, "admin/bannedPost", new Callback() {
                @Override
                public void onFailure(@NonNull Call call, @NonNull IOException e) {
                    e.printStackTrace();
                }
                @Override
                public void onResponse(@NonNull Call call, @NonNull Response response) {
                runOnUiThread(() -> {
                    try {
                        Tools.toast( new JSONObject(response.body().string()).getString("datalist"));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    finish();
                });
                }
            });
        });
        binding.postDetailBanAccount.setOnClickListener(v -> {
            List<HttpParaBean> para=new ArrayList<>();
            para.add(new HttpParaBean("token",""));
            para.add(new HttpParaBean("id",String.valueOf(MyApplication.postBean.bu_id)));
            Network.post(para, "admin/bannedUser", new Callback() {
                @Override
                public void onFailure(@NonNull Call call, @NonNull IOException e) {
                    e.printStackTrace();
                }
                @Override
                public void onResponse(@NonNull Call call, @NonNull Response response) {
                    runOnUiThread(() -> {
                        try {
                            JSONObject jo=new JSONObject(response.body().string());
                            Tools.toast( jo.getString("datalist"));
                            if (jo.getInt("code")==2){
                                PostDetailActivity.this.finish();
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    });
                }
            });
        });
        binding.postDetailCollect.setOnClickListener(view -> {
            List<HttpParaBean> para=new ArrayList<>();
            para.add(new HttpParaBean("token","token"));
            para.add(new HttpParaBean("bpId",String.valueOf(MyApplication.postBean.id)));
            Network.post(para, "wbhMain/handleCollect", new Callback() {
                @Override
                public void onFailure(@NonNull Call call, @NonNull IOException e) {
                    e.printStackTrace();
                }
                @Override
                public void onResponse(@NonNull Call call, @NonNull Response response) {
                    runOnUiThread(() -> {
                        try {
                            Tools.toast( new JSONObject(Objects.requireNonNull(response.body()).string()).getString("datalist"));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    });
                }
            });

        });
        binding.postDetailMore.setOnClickListener(this::showPopupMenu);
        addViews();
        getUserInfo();
        TTAdNative mTTAdNative = TTAdSdk.getAdManager().createAdNative(this);
        mTTAdNative.loadBannerExpressAd(new AdSlot.Builder().setCodeId("946890673").setAdCount(1).setImageAcceptedSize(600, 300).setSupportDeepLink(true).build(), new TTAdNative.NativeExpressAdListener() {
                    @Override
                    public void onError(int i, String s) {
                    }
                    @Override
                    public void onNativeExpressAdLoad(List<TTNativeExpressAd> ads) {
                        if (ads.size() == 0) return;
                        TTNativeExpressAd ad = ads.get(0);
                        ad.setExpressInteractionListener(new TTNativeExpressAd.ExpressAdInteractionListener() {
                            @Override
                            public void onAdClicked(View view, int type) {

                            }
                            @Override
                            public void onAdShow(View view, int type) {
                            }
                            @Override
                            public void onRenderFail(View view, String msg, int code) {
                            }
                            @Override
                            public void onRenderSuccess(View view, float width, float height) {
                                binding.postDetailBanner.setVisibility(View.VISIBLE);
                                binding.postDetailBanner.addView(view);
                            }
                        });
                        ad.setDislikeCallback(PostDetailActivity.this, new TTAdDislike.DislikeInteractionCallback() {
                            @Override
                            public void onShow() { }

                            @Override
                            public void onSelected(int i, String s, boolean b) {
                                binding.postDetailBanner.setVisibility(View.GONE);
                            }
                            @Override
                            public void onCancel() { }
                        });
                        ad.render();
                    }
                });
    }
    private void showPopupMenu(View view) {
        PopupMenu popupMenu = new PopupMenu(this, view);
        popupMenu.getMenuInflater().inflate(R.menu.post_detail, popupMenu.getMenu());
        popupMenu.setOnMenuItemClickListener(item -> {
            if (item.getItemId()==R.id.menu_tipoff){
                startActivity(new Intent(PostDetailActivity.this,TipoffActivity.class));
            }
            if(item.getItemId()==R.id.menu_addToBlacklist){
                List<HttpParaBean> para=new ArrayList<>();
                para.add(new HttpParaBean("token","token"));
                para.add(new HttpParaBean("wcId",String.valueOf(MyApplication.postBean.bu_id)));
                Network.post(para, "wbhMain/pullBack", new Callback() {
                    @Override
                    public void onFailure(@NonNull Call call, @NonNull IOException e) {
                        e.printStackTrace();
                    }
                    @Override
                    public void onResponse(@NonNull Call call, @NonNull Response response) {
                        runOnUiThread(() -> {
                            try {
                                Tools.toast( new JSONObject(Objects.requireNonNull(response.body()).string()).getString("datalist"));
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        });
                    }
                });
            }
            return false;
        });
        popupMenu.show();
    }
    private void lookAd(ChildClick click) {
        if (dialog==null){
            dialog = new ProgressDialog(this);
            dialog.setTitle(this.getString(R.string.tips));
            dialog.setCanceledOnTouchOutside(false);
            dialog.setMessage(this.getString(R.string.loading));
        }
        dialog.show();
        TTAdNative mTTAdNative = TTAdSdk.getAdManager().createAdNative(this);
        AdSlot adSlot = new AdSlot.Builder().setCodeId("946899756").setMediaExtra(MyApplication.sp.getString("token","")).setSupportDeepLink(true).setRewardName("Ticket").setRewardAmount(1).setUserID("user0").setExpressViewAcceptedSize(500,500).setOrientation(TTAdConstant.VERTICAL).build();
        mTTAdNative.loadRewardVideoAd(adSlot, new TTAdNative.RewardVideoAdListener() {
            @Override
            public void onError(int code, String message) {
                dialog.dismiss();
            }
            @Override
            public void onRewardVideoCached(TTRewardVideoAd ttRewardVideoAd) {
                dialog.dismiss();
                ttRewardVideoAd.showRewardVideoAd(PostDetailActivity.this);
            }
            @Override
            public void onRewardVideoAdLoad(TTRewardVideoAd ad) {
                ad.setRewardAdInteractionListener(new TTRewardVideoAd.RewardAdInteractionListener() {
                    @Override
                    public void onAdShow() { }
                    @Override
                    public void onAdVideoBarClick() { }
                    @Override
                    public void onAdClose() { click.click(null,0); }
                    @Override
                    public void onVideoComplete() { }
                    @Override
                    public void onVideoError() { }
                    @Override
                    public void onRewardVerify(boolean rewardVerify, int rewardAmount, String rewardName, int i1, String s1) {
                        if (rewardVerify) Tools.toast( getString(R.string.congratulation));
                    }
                    @Override
                    public void onSkippedVideo() {
                    }
                });
            }
            @Override
            public void onRewardVideoCached() {
            }
        });
    }

    private void reply2(int pi) {
        CommentDetailBean bean = data.get(pi).commentDetailBean;
        BottomSheetDialog dialog = new BottomSheetDialog(PostDetailActivity.this);
        @SuppressLint("InflateParams") View commentView = LayoutInflater.from(PostDetailActivity.this).inflate(R.layout.dialog_reply,null);
        final EditText commentText = commentView.findViewById(R.id.dialog_comment_et);
        final Button bt_comment = commentView.findViewById(R.id.dialog_comment_bt);
        commentText.setHint(getResources().getString(R.string.reply2)+ " "+bean.wb_nickname );
        dialog.setContentView(commentView);
        dialog.show();
        bt_comment.setOnClickListener(view1 -> {
            dialog.dismiss();
            String content = commentText.getText().toString();
            if (content.equals("")){
                Tools.toast( getResources().getString(R.string.content_cant_blank));
            }else{
                List<HttpParaBean> para=new ArrayList<>();
                para.add(new HttpParaBean("token","token"));
                para.add(new HttpParaBean("bpId",String.valueOf(bean.bp_id)));
                para.add(new HttpParaBean("commentId",String.valueOf(data.get(pi).commentDetailBean.id)));
                para.add(new HttpParaBean("replyContent",commentText.getText().toString()));
                para.add(new HttpParaBean("replyNickname", ""));
                Network.post(para, "wbhMain/reply", new Callback() {
                    @Override
                    public void onFailure(@NonNull Call call, @NonNull IOException e) {
                        e.printStackTrace();
                    }
                    @Override
                    public void onResponse(@NonNull Call call, @NonNull Response response) {
                        try {
                            Tools.toast( new JSONObject(response.body().string()).getString("datalist"));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        refreshComment(true,null,null);
                    }
                });
            }
        });
    }
    private void reply(int i,int i1) {
        ReplyDetailBean bean = data.get(i).replyDetailBeans.get(i1);
        BottomSheetDialog dialog = new BottomSheetDialog(PostDetailActivity.this);
        @SuppressLint("InflateParams") View commentView = LayoutInflater.from(PostDetailActivity.this).inflate(R.layout.dialog_reply,null);
        final EditText commentText = commentView.findViewById(R.id.dialog_comment_et);
        final Button bt_comment = commentView.findViewById(R.id.dialog_comment_bt);
        commentText.setHint(getResources().getString(R.string.reply2)+" "+ bean.reply_nickname);
        dialog.setContentView(commentView);
        bt_comment.setOnClickListener(view1 -> {
            commentText.setText("");
            dialog.dismiss();
            String content = commentText.getText().toString().trim().replace("\n","");
            if (content.equals("")){
                Tools.toast( getResources().getString(R.string.content_cant_blank));
            }else {
                List<HttpParaBean> para=new ArrayList<>();
                para.add(new HttpParaBean("token","token"));
                para.add(new HttpParaBean("bpId",String.valueOf(bean.bp_id)));
                para.add(new HttpParaBean("commentId",String.valueOf(data.get(i).commentDetailBean.id)));
                para.add(new HttpParaBean("replyContent",content));
                para.add(new HttpParaBean("replyNickname", bean.wb_nickname));
                Network.post(para, "wbhMain/reply", new Callback() {
                    @Override
                    public void onFailure(@NonNull Call call, @NonNull IOException e) {
                        e.printStackTrace();
                    }
                    @Override
                    public void onResponse(@NonNull Call call, @NonNull Response response) {
                        try {
                            Tools.toast( new JSONObject(response.body().string()).getString("datalist"));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        refreshComment(true,null,null);
                    }
                });
            }
        });
        dialog.show();
    }
    private void comment() {
        List<HttpParaBean> para=new ArrayList<>();
        para.add(new HttpParaBean("token","token"));
        para.add(new HttpParaBean("bpId",MyApplication.postBean.id));
        para.add(new HttpParaBean("wcContent",binding.postDetailCommentEdit.getText().toString().trim().replace("\n","")));
        binding.postDetailCommentEdit.setText("");
        Network.post(para, "wbhMain/postComment", new Callback() {
            @Override
            public void onFailure(@NonNull Call call, @NonNull IOException e) {
                e.printStackTrace();
            }
            @Override
            public void onResponse(@NonNull Call call, @NonNull Response response) {
                runOnUiThread(() -> {
                    try {
                        Tools.toast( new JSONObject(response.body().string()).getString("datalist"));
                        binding.postDetailCommentEdit.setText("");
                        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.hideSoftInputFromWindow(binding.postDetailCommentEdit.getWindowToken(),0);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    refreshComment(true,null,null);
                });
            }
        });
    }
    private void getUserInfo() {
        ArrayList<HttpParaBean> list=new ArrayList<>();
        list.add(new HttpParaBean("token", "token"));
        Network.post(list, "wbh/userInfo", new Callback() {
            @SuppressLint({"StringFormatMatches", "SetTextI18n"})
            @Override
            public void onResponse(@NonNull Call call, @NonNull Response response) {
             runOnUiThread(() -> {
                    try {
                        JSONObject jo = new JSONObject(response.body().string());
                        if (jo.getInt("code")==1){
                            JSONObject jo1 = jo.getJSONArray("datalist").getJSONObject(0);
                            if (jo1.getInt("is_admin")==1){
                                binding.postDetailPara.setText(String.format(getString(R.string.viewsNum),MyApplication.postBean.bp_click_number+1)+"    "+ String.format(getResources().getString(R.string.tip_off_num),MyApplication.postBean.bp_report)+"    "+ String.format(getResources().getString(R.string.banned_count),MyApplication.postBean.bannedCount));
                                binding.postDetailAdminButton.setVisibility(View.VISIBLE);
                            }else {
                                binding.postDetailPara.setText(String.format(getString(R.string.viewsNum),MyApplication.postBean.bp_click_number+1));
                                binding.postDetailAdminButton.setVisibility(View.GONE);
                            }
                        }else {
                            binding.postDetailPara.setText(String.format(getString(R.string.viewsNum),MyApplication.postBean.bp_click_number+1));
                            binding.postDetailAdminButton.setVisibility(View.GONE);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                });
            }
            @Override
            public void onFailure(@NonNull Call call, @NonNull IOException e) {
                e.printStackTrace();
            }
        });
    }
    private void addViews() {
        List<HttpParaBean> para=new ArrayList<>();
        para.add(new HttpParaBean("id",MyApplication.postBean.id));
        Network.post(para, "wbhMain/incClick", new Callback() {
            @Override
            public void onFailure(@NonNull Call call, @NonNull IOException e) {
                e.printStackTrace();
                refreshComment(true,null,null);
            }
            @Override
            public void onResponse(@NonNull Call call, @NonNull Response response) {
                refreshComment(true,null,null);
            }
        });
    }
    private void refreshComment(boolean isrefresh,RefreshLayout loadmore,RefreshLayout refresh) {
        List<HttpParaBean> para=new ArrayList<>();
        para.add(new HttpParaBean("bpId",String.valueOf(MyApplication.postBean.id)));
        if (isrefresh){
            data.clear();
            current=1;
        }else {
            current++;
        }
        para.add(new HttpParaBean("current",String.valueOf(current)));
        para.add(new HttpParaBean("size","10"));
        Network.post(para, "wbhMain/getComments", new Callback() {
            @Override
            public void onFailure(@NonNull Call call, @NonNull IOException e) {
                e.printStackTrace();
            }
            @Override
            public void onResponse(@NonNull Call call, @NonNull Response response) {
                runOnUiThread(() -> {
                    try {
                        JSONArray ja = new JSONObject(response.body().string()).getJSONArray("datalist");
                        for (int i = 0; i < ja.length(); i++) {
                            JSONObject jo = ja.getJSONObject(i);
                            data.add(new CommentBean(
                                    new CommentDetailBean(jo.getInt("bp_id"), jo.getInt("bu_id"), jo.getInt("id"), jo.getInt("reply_number"), jo.getString("time"), jo.getString("wb_nickname"), jo.getString("wb_url"), jo.getString("wc_content")),
                                    new ArrayList<>()
                            ));
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    adp.notifyDataSetChanged();
                    if (loadmore!=null)loadmore.finishLoadMore();
                    if (refresh!=null)refresh.finishRefresh();
                });
            }
        });
    }
}